use std::fmt::Display;

#[derive(Debug)]
pub enum MyError {
    ReadStreamError(std::io::Error),
    ReadStreamNoneError,
}

impl PartialEq for MyError {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (MyError::ReadStreamError(_), MyError::ReadStreamError(_)) => true,
            (MyError::ReadStreamNoneError, MyError::ReadStreamNoneError) => true,
            _ => false,
        }
    }
}
impl Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            MyError::ReadStreamError(e) => write!(f, "ReadStreamError: {}", e),
            MyError::ReadStreamNoneError => write!(f, "ReadStreamNoneError"),
        }
    }
}

impl From<std::io::Error> for MyError {
    fn from(e: std::io::Error) -> Self {
        MyError::ReadStreamError(e)
    }
}

impl From<serde_json::Error> for MyError {
    fn from(value: serde_json::Error) -> Self {
        MyError::ReadStreamError(std::io::Error::new(std::io::ErrorKind::Other, value.to_string()))
    }
}